import request from '@/libs/request';
let _self;
export const index =  {
	props: {
		show: {type: Boolean,default: false},
		title: {type: String,default: ""},
		payData:{type: Object,default: {}}
	},
	data() {
		return {
			host:process.env.HOST,
			showBox:false,
			boxTitle:this.title,
			dataList:[],
			payIndex:0,
			codeList:[],
			codeIndex:0,
			codeImg:"",
			showConfirm:false,
			rules:{}
		}
	},
	
	
	watch:{
		show(val){
			this.showBox=val;
			if(val){
				this.initData();
			}
		},
		
	
		showBox(val){
			this.$emit('update:show', val);
		},
		title(val){this.boxTitle=val;},

	},
	created() {
		_self = this;

	},
	
	methods: {
		async initData(){

			this.dataList = await request({url: '/api/User/getPayCode',method: 'GET',data:{}});
			console.log(this.dataList.length);
			this.setCodeList();
		},
		
		setCodeList(){
			if(!this.dataList||this.dataList.length==0) return false;
			let picsList=this.dataList[this.payIndex]["specs"];
			if(!picsList||picsList.length==0) return false;
			this.codeIndex=0;
			this.codeList=[];
			for(let index in picsList){
				let pic=picsList[index]["pics"]?picsList[index]["pics"][0].url:"";
				this.codeList.push({"name":picsList[index].name,"pic":pic});
			}	
			this.setCodeImg();
			
		},
		
		setCodeImg(){	
			this.payData["pay_type"]=this.codeList[this.codeIndex].name;
			this.codeImg=this.codeList[this.codeIndex]["pic"];
		},
		
		
		
		cancel(e){
			this.showBox=false;
		},
		confirmBox(e){
			this.showConfirm=true;
			
		},
		submitForm(){
			
		},
		
		selectChange: function(e) {
			let index=e.detail.value;
			let key=e.currentTarget.dataset["key"];
			console.log(key);
			switch(key){
				case "code_name":
					this.payIndex=index;
					this.setCodeList();
				break;
				case "code_type":
					this.codeIndex=index;
					this.setCodeImg();
				break;
			}
		},
		
		confirmCode: function() {	
			let payInfo=Object.assign({"confirm":true},this.payData);
			this.showBox=false;
			this.$emit('update:payData',{});
			this.$emit('update:payData',payInfo);
		}

	}
}